﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls.Maps.Core;
using Microsoft.Phone.Tasks;
using System.Device.Location;

// Additional Libraries
using Microsoft.Phone.Notification;
using System.IO.IsolatedStorage;

using Microsoft.Phone.Shell;
using Microsoft.Phone.Net.NetworkInformation;

using LocalDatabase.Model;
using LocalDatabase.ViewModel;
using System.Windows.Controls.Primitives;

namespace FindMe
{
    public partial class contact : PhoneApplicationPage
    {
        public Color ApplicationBarColor = Color.FromArgb(255, 118, 118, 118);
        public string contactBlock = "block", imgContactBlock = "/Icons/0block.png";
        public contact()
        {
            InitializeComponent();
            anyNews();
            SetAppBar();
        }
        
        private void btnHome_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(App.PathMain, UriKind.Relative));
        }

        private void btnInbox_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(App.PathConversations, UriKind.Relative));
        }

        private void btnRequests_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(App.PathNotifications, UriKind.Relative));
        }



        private void lastLocationBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            LabeledMapLocation start = new LabeledMapLocation();
            start.Label = App.UserCoordinates;

            LabeledMapLocation end = new LabeledMapLocation();
            end.Label = "18.24, -66.10";

            BingMapsDirectionsTask x = new BingMapsDirectionsTask();
            x.Start = start;
            x.End = end;
            x.Show();
        }

        private void chatBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(App.PathChat, UriKind.Relative));
        }



        private void SetAppBar()
        {
            ApplicationBar = new ApplicationBar()
            {
                IsVisible = true,
                Mode = ApplicationBarMode.Default,
                IsMenuEnabled = true,
                Opacity = 100,
                BackgroundColor = ApplicationBarColor
            };


            ApplicationBarIconButton appCall = new ApplicationBarIconButton()
            {
                IconUri = new Uri("/Icons/0call.png", UriKind.Relative),
                Text = "call",
                IsEnabled = true
            };
            ApplicationBar.Buttons.Add(appCall);
            appCall.Click += new EventHandler(appCall_Click);

            ApplicationBarIconButton appBlock = new ApplicationBarIconButton()
            {
                IconUri = new Uri(imgContactBlock, UriKind.Relative),
                
                Text = contactBlock,
                IsEnabled = true
                
            };
            ApplicationBar.Buttons.Add(appBlock);
            appBlock.Click += new EventHandler(appBlock_Click);


            ApplicationBarIconButton appShareLocation = new ApplicationBarIconButton()
            {
                IconUri = new Uri("/Icons/0appbar.share.png", UriKind.Relative),
                Text = "share location",
                IsEnabled = true
            };
            ApplicationBar.Buttons.Add(appShareLocation);
            appShareLocation.Click +=new EventHandler(appShareLocation_Click);

            ApplicationBarIconButton appDelete = new ApplicationBarIconButton()
            {
                IconUri = new Uri("/Icons/0newcancel.png", UriKind.Relative),
                Text = "delete",
                IsEnabled = true
            };
            ApplicationBar.Buttons.Add(appDelete);
            appDelete.Click += new EventHandler(appDelete_Click);
        }

        
        private void anyNews()
        {
            if (App.counterInbox <= 0)
            {
                borderInbox.Visibility = Visibility.Collapsed;
            }
            else
            {
                borderInbox.Visibility = Visibility.Visible;
                countInbox.Text = App.counterInbox.ToString();
            }
            if (App.counterRequest == 0)
            {
                borderRequest.Visibility = Visibility.Collapsed;
            }
            else
            {
                borderRequest.Visibility = Visibility.Visible;
                countRequest.Text = App.counterRequest.ToString();
            }
        }

        private void appCall_Click(object sender, EventArgs e)
        {
            
        var pt = new PhoneCallTask();
        pt.DisplayName = "Jonás Martínez";
        pt.PhoneNumber = "7876192394";
        pt.Show();

        }

        private void appBlock_Click(object sender, EventArgs e)
        {
            if (contactBlock == "block") { contactBlock = "unblock"; imgContactBlock = "/Icons/0unblock.png"; MessageBox.Show("You blocked Jonás Martínez, now he/she can't see you :("); } else { contactBlock = "block"; imgContactBlock = "/Icons/0block.png"; MessageBox.Show("You unblocked Jonás Martínez, now he/she can see you again :)"); }//JAJAJA asi codifíco yo :P
            SetAppBar();
        }
                
        private void appShareLocation_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri(App.PathShare, UriKind.Relative));
        }   

        private void appDelete_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You want to delete Jonás Martínez from your friends?");
        }
       
    }
}